package com.qax.scheduler.spring.boot.autoconfigure;

import com.qax.scheduler.spring.boot.autoconfigure.properties.JobSourceProperties;
import com.qax.task.timer.core.JobSourceReporter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;

import java.util.NoSuchElementException;

/**
 *
 * @author leiliang
 */
public class JobSourceReporterWrapper extends JobSourceReporter implements InitializingBean {

   @Autowired
   private JobSourceProperties jobMinaSourceProperties;


    @Override
    public void afterPropertiesSet() {
        if (!super.isUsedHeartBeatLease()){
            super.setUsedHeartBeatLease(jobMinaSourceProperties.isUsedHeartBeatLease());
        }
        if (super.getEtcdAddress() == null){
            if (jobMinaSourceProperties.getEtcdAddress() == null || jobMinaSourceProperties.getEtcdAddress().isEmpty()){
                throw new NoSuchElementException("Etcd address url is not empty");
            }
            super.setEtcdAddress(jobMinaSourceProperties.getEtcdAddress());
        }
        if (super.getReportInterfaceUrl() == null){
            if (jobMinaSourceProperties.getReportInterfaceUrl() == null || jobMinaSourceProperties.getReportInterfaceUrl().isEmpty()){
                throw new NoSuchElementException("reportInterfaceUrl is not empty");
            }
           super.setReportInterfaceUrl(jobMinaSourceProperties.getReportInterfaceUrl());
        }
        if (super.getReportInterfaceUrl() == null){
            if (jobMinaSourceProperties.getUpdateStatusRealTimeUrl() == null || jobMinaSourceProperties.getUpdateStatusRealTimeUrl().isEmpty()){
                throw new NoSuchElementException("updateStatusRealTimeUrl is not empty");
            }
            super.setUpdateStatusRealTimeUrl(jobMinaSourceProperties.getUpdateStatusRealTimeUrl());
        }
    }
}
